package com.hswealth;

import java.awt.Frame;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

/**
 *    @author    daixf41752
 *    @Date 2021-09-09 11:03:57    
 *		定义一个玩家
 */
public class Player extends KeyAdapter{
	
	GameFrame gameFrame;
	
	public Player(GameFrame gameFrame) {
		super();
		this.gameFrame = gameFrame;
	}

	@Override
	public void keyPressed(KeyEvent e) {
		int keyCode = e.getKeyCode();
		//上下左右：38,40,37,39
		switch (keyCode) {
		case 38:
			gameFrame.heroPlane.up = true;
			break;
		case 40:
			gameFrame.heroPlane.down = true;
			break;
		case 37:
			gameFrame.heroPlane.left = true;
			break;
		case 39:
			gameFrame.heroPlane.right = true;
			break;
		case 66:
			addBullet();
			break;
		}
	}

	@Override
	public void keyReleased(KeyEvent e) {
		int keyCode = e.getKeyCode();
		//上下左右：38,40,37,39
		switch (keyCode) {
		case 38:
			gameFrame.heroPlane.up = false;
			break;
		case 40:
			gameFrame.heroPlane.down = false;
			break;
		case 37:
			gameFrame.heroPlane.left = false;
			break;
		case 39:
			gameFrame.heroPlane.right = false;
			break;
		}
	}
	
	/**
	 * 飞机装弹
	 */
	public void addBullet() {
		gameFrame.bullets.add(new Bullet(gameFrame.heroPlane.x+6, gameFrame.heroPlane.y-20));
	}

}
